<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:cc="http://java.sun.com/jsf/composite"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:x="http://xpert.com/faces"
      xmlns:h="http://java.sun.com/jsf/html">

    <!-- INTERFACE -->
    <cc:interface>
        <cc:attribute name="for" required="true" />
        <cc:attribute name="forClass" required="java.lang.Class" />
        <cc:attribute name="collapsed" type="java.lang.Boolean" default="true" />
        <cc:attribute name="buttonStyleClass" type="java.lang.String"  />
        <cc:attribute name="panelStyleClass" type="java.lang.String"  />
        <cc:attribute name="buttonIcon" type="java.lang.String" default="ui-icon-plus" />
    </cc:interface>

    <!-- IMPLEMENTATION -->
    <cc:implementation>
        <h:outputStylesheet library="xpert" name="css/style.css" />
        <h:outputScript library="xpert" name="scripts/core.js" target="head" />
        <span id="#{cc.attrs.clientId}">
            <h:panelGroup rendered="#{auditBean.isPersisted(cc.attrs.for)}" id="auditingPanel">
                <h:panelGroup id="detail">

                    <p:commandButton process="@this" action="#{auditBean.detail}" icon="#{cc.attrs.buttonIcon}"
                                     rendered="#{cc.attrs.collapsed}"
                                     styleClass="button-detail-auditing #{cc.attrs.buttonStyleClass}"
                                     oncomplete="$(PrimeFaces.escapeClientId('#{cc.attrs.clientId}')).find('.button-detail-auditing').hide();$(PrimeFaces.escapeClientId('#{cc.attrs.clientId}')).find('.panel-detail-auditing').show()"
                                     update="accordionDetail" value="#{xmsg.auditing}" >
                        <f:setPropertyActionListener value="#{cc.attrs.for}" target="#{auditBean.object}" />
                    </p:commandButton>

                    <h:panelGroup rendered="#{not cc.attrs.collapsed}">
                        <f:event type="preRenderComponent" listener="#{auditBean.detail(cc.attrs.for)}" />
                    </h:panelGroup>

                    <h:panelGroup styleClass="panel-detail-auditing #{cc.attrs.panelStyleClass}" style="#{cc.attrs.collapsed ? 'display: none;' : ''}" >
                        <p:accordionPanel id="accordionDetail" >
                            <p:tab title="#{xmsg.auditingDetail}">
                                <ui:param name="xpertAuditingDetail" value="#{auditBean.getDetailAuditBean(cc.attrs.for)}"/>
                                <h:panelGroup rendered="#{auditBean.primeFaces3}">
                                    <p:dataTable var="audit" value="#{xpertAuditingDetail.auditings}" styleClass="datatable-auditing"
                                                 rendered="#{not empty xpertAuditingDetail.auditings}"
                                                 emptyMessage="#{xmsg.noRecordFound}"  
                                                 lazy="true"
                                                 rowsPerPageTemplate="10,20,30" rowIndexVar="index"
                                                 paginator="true" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                                 currentPageReportTemplate=" "
                                                 rows="10" paginatorPosition="bottom" >

                                        <p:column style="width: 20px;">
                                            <button type="button" title="#{xmsg.detail}" onclick="Xpert.detailAuditTable(this);"
                                                    class="button-detail-audit ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" >
                                                <span class="ui-button-icon-left ui-icon ui-icon-plus"></span>
                                                <span class="ui-button-text">ui-button</span>
                                            </button>
                                        </p:column>
                                        <p:column style="text-align: center;" sortBy="#{audit.eventDate}" headerText="#{xmsg.date}"  >
                                            <h:outputText value="#{audit.eventDate}" >
                                                <f:convertDateTime dateStyle="medium" type="both"/>
                                            </h:outputText>
                                        </p:column>
                                        <p:column style="text-align: center;" sortBy="#{audit.auditingType}" headerText="#{xmsg.type}" >
                                            <h:outputText value="#{xmsg[audit.auditingType.description]}" />
                                        </p:column>
                                        <p:column headerText="#{xmsg['user']}">
                                            <h:outputText value="#{audit.userName}" />
                                        </p:column>
                                        <p:column headerText="#{xmsg['ip']}">
                                            <h:outputText value="#{audit.ip}" />
                                        </p:column>
                                        <p:summaryRow>  
                                            <p:column colspan="5">  
                                                <p:dataTable var="metadata" emptyMessage="#{xmsg.noRecordFound}"
                                                             value="#{audit.metadatas}" rowIndexVar="indexMetadata">
                                                    <x:initializer/>
                                                    <p:column style="text-align: center;">
                                                        <h:outputText value="#{indexMetadata+1}" />
                                                    </p:column>
                                                    <p:column headerText="#{xmsg.field}">
                                                        <h:outputText value="#{metadata.getFieldName(empty cc.attrs.forClass ? cc.attrs.for.getClass() : cc.attrs.forClass)}" />
                                                    </p:column>
                                                    <p:column headerText="#{xmsg.oldValue}">
                                                        <h:outputText value="#{metadata.oldValue}" />
                                                    </p:column>
                                                    <p:column headerText="#{xmsg.newValue}">
                                                        <h:outputText value="#{metadata.newValue}" />
                                                    </p:column>
                                                </p:dataTable>
                                            </p:column>
                                        </p:summaryRow>
                                    </p:dataTable>
                                </h:panelGroup>
                                <h:panelGroup rendered="#{not auditBean.primeFaces3}">

                                    <h:panelGroup rendered="#{auditBean.primeFaces4}">
                                        <p:dataTable var="audit" value="#{xpertAuditingDetail.auditings}" styleClass="datatable-auditing"
                                                     rendered="#{not empty xpertAuditingDetail.auditings}"
                                                     emptyMessage="#{xmsg.noRecordFound}"  
                                                     lazy="true" sortBy="eventDate" sortOrder="descending"
                                                     rowsPerPageTemplate="10,20,30" rowIndexVar="index"
                                                     paginator="true" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                                     currentPageReportTemplate=" "
                                                     rows="10" paginatorPosition="bottom" >

                                            <p:column style="width: 20px;">
                                                <button type="button" title="#{xmsg.detail}" onclick="Xpert.detailAuditTable(this);"
                                                        class="button-detail-audit ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" >
                                                    <span class="ui-button-icon-left ui-icon ui-icon-plus"></span>
                                                    <span class="ui-button-text">ui-button</span>
                                                </button>
                                            </p:column>
                                            <p:column style="text-align: center;" sortBy="#{audit.eventDate}" headerText="#{xmsg.date}"  >
                                                <h:outputText value="#{audit.eventDate}" >
                                                    <f:convertDateTime dateStyle="medium" type="both"/>
                                                </h:outputText>
                                            </p:column>
                                            <p:column style="text-align: center;" sortBy="#{audit.auditingType}" headerText="#{xmsg.type}" >
                                                <h:outputText value="#{xmsg[audit.auditingType.description]}" />
                                            </p:column>
                                            <p:column headerText="#{xmsg['user']}">
                                                <h:outputText value="#{audit.userName}" />
                                            </p:column>
                                            <p:column headerText="#{xmsg['ip']}">
                                                <h:outputText value="#{audit.ip}" />
                                            </p:column>
                                            <p:summaryRow>  
                                                <p:column colspan="5">  
                                                    <p:dataTable var="metadata" emptyMessage="#{xmsg.noRecordFound}"
                                                                 value="#{audit.metadatas}" rowIndexVar="indexMetadata">
                                                        <x:initializer/>
                                                        <p:column style="text-align: center;">
                                                            <h:outputText value="#{indexMetadata+1}" />
                                                        </p:column>
                                                        <p:column headerText="#{xmsg.field}">
                                                            <h:outputText value="#{metadata.getFieldName(empty cc.attrs.forClass ? cc.attrs.for.getClass() : cc.attrs.forClass)}" />
                                                        </p:column>
                                                        <p:column headerText="#{xmsg.oldValue}">
                                                            <h:outputText value="#{metadata.oldValue}" />
                                                        </p:column>
                                                        <p:column headerText="#{xmsg.newValue}">
                                                            <h:outputText value="#{metadata.newValue}" />
                                                        </p:column>
                                                    </p:dataTable>
                                                </p:column>
                                            </p:summaryRow>
                                        </p:dataTable>
                                    </h:panelGroup>
                                    <h:panelGroup rendered="#{not auditBean.primeFaces4}">
                                        <p:dataTable var="audit" value="#{xpertAuditingDetail.auditings}" styleClass="datatable-auditing"
                                                     rendered="#{not empty xpertAuditingDetail.auditings}"
                                                     emptyMessage="#{xmsg.noRecordFound}"  
                                                     lazy="true" sortBy="#{audit.eventDate}" sortOrder="descending"
                                                     rowsPerPageTemplate="10,20,30" rowIndexVar="index"
                                                     paginator="true" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                                     currentPageReportTemplate=" "
                                                     rows="10" paginatorPosition="bottom" >

                                            <p:column style="width: 20px;">
                                                <button type="button" title="#{xmsg.detail}" onclick="Xpert.detailAuditTable(this);"
                                                        class="button-detail-audit ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" >
                                                    <span class="ui-button-icon-left ui-icon ui-icon-plus"></span>
                                                    <span class="ui-button-text">ui-button</span>
                                                </button>
                                            </p:column>
                                            <p:column style="text-align: center;" sortBy="#{audit.eventDate}" headerText="#{xmsg.date}"  >
                                                <h:outputText value="#{audit.eventDate}" >
                                                    <f:convertDateTime dateStyle="medium" type="both"/>
                                                </h:outputText>
                                            </p:column>
                                            <p:column style="text-align: center;" sortBy="#{audit.auditingType}" headerText="#{xmsg.type}" >
                                                <h:outputText value="#{xmsg[audit.auditingType.description]}" />
                                            </p:column>
                                            <p:column headerText="#{xmsg['user']}">
                                                <h:outputText value="#{audit.userName}" />
                                            </p:column>
                                            <p:column headerText="#{xmsg['ip']}">
                                                <h:outputText value="#{audit.ip}" />
                                            </p:column>
                                            <p:summaryRow>  
                                                <p:column colspan="5">  
                                                    <p:dataTable var="metadata" emptyMessage="#{xmsg.noRecordFound}"
                                                                 value="#{audit.metadatas}" rowIndexVar="indexMetadata">
                                                        <x:initializer/>
                                                        <p:column style="text-align: center;">
                                                            <h:outputText value="#{indexMetadata+1}" />
                                                        </p:column>
                                                        <p:column headerText="#{xmsg.field}">
                                                            <h:outputText value="#{metadata.getFieldName(empty cc.attrs.forClass ? cc.attrs.for.getClass() : cc.attrs.forClass)}" />
                                                        </p:column>
                                                        <p:column headerText="#{xmsg.oldValue}">
                                                            <h:outputText value="#{metadata.oldValue}" />
                                                        </p:column>
                                                        <p:column headerText="#{xmsg.newValue}">
                                                            <h:outputText value="#{metadata.newValue}" />
                                                        </p:column>
                                                    </p:dataTable>
                                                </p:column>
                                            </p:summaryRow>
                                        </p:dataTable>
                                    </h:panelGroup>
                                </h:panelGroup>
                            </p:tab>
                        </p:accordionPanel>
                    </h:panelGroup>
                </h:panelGroup>
            </h:panelGroup>
        </span>
    </cc:implementation>
</html>